﻿using HDS.DistributorApi.Core;
using HDS.DistributorApi.Core.Entity;
using HDS.IService.Log;
using HDS.Model;
using HDS.Model.Entity.Master;
using HDS.Model.Entity.View;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace HDS.DistributorApi.Ctrip
{
    public class DistributorPushApi : IDistributorPushApi
    {
        private readonly ILogger _ILogger;
        private readonly IApiLogService _IApiLogService;

        public DistributorPushApi(ILogger ilogger, IApiLogService iapiLogService)
        {
            _ILogger = ilogger;
            _IApiLogService = iapiLogService;
        }

        public async Task LoadConfig(DistributorConfig config)
        {
           //throw new NotImplementedException();
        }

        public async Task<ResultData<string>> PushConfirmRoom(string distributor, string distributorOrderId, string orderId)
        {
            return new ResultData<string> { Success = true };
            //return new ResultData<string> { Success = false, Code = ErrorCode.ApiError, Message = "测试推送失败" };
        }

        public async Task<ResultData<VDistributorHotel>> PushDeleteHotel(string distributor, VDistributorHotel hotelInfo)
        {
            hotelInfo.PushStatus = PushStatus.GetResult;
            hotelInfo.PushResult = PushResult.Deactivated;
            return new ResultData<VDistributorHotel> { Success = true, Data = hotelInfo };
        }

        public async Task<ResultData<string>> PushHotelConfirmNo(string distributor, string distributorOrderId, string orderId, string hotelConfirmNo)
        {
            return new ResultData<string> { Success = true };
        }

        public async Task<ResultData<VDistributorHotel>> PushHotelInfo(string distributor, VDistributorHotel hotelInfo)
        {
            hotelInfo.PushStatus = PushStatus.Pushed;
            if (hotelInfo.PushResult == PushResult.NotPush)
                hotelInfo.PushResult = PushResult.Pushed;
            return new ResultData<VDistributorHotel> { Success = true, Data = hotelInfo };
        }

        public async Task<ResultData<List<VDistributorRoom>>> PushRoomInfo(string distributor, List<VDistributorRoom> roomList)
        {
            roomList.ForEach(item => {
                item.PushStatus = PushStatus.Pushed;
                if (item.PushResult == PushResult.NotPush)
                    item.PushResult = PushResult.Pushed;
            });
            return new ResultData<List<VDistributorRoom>> { Success = true, Data = roomList };
        }

        public async Task<ResultData<CDistributorHotel>> QueryPushResult(string distributor, VDistributorHotel hotelInfo, List<VDistributorRoom> roomList)
        {
            hotelInfo.PushStatus = PushStatus.GetResult;
            hotelInfo.PushResult = PushResult.Active;
            hotelInfo.DistributorHotelId = "XXX" + hotelInfo.HotelId;
            roomList.ForEach(item => {
                item.PushStatus = PushStatus.GetResult;
                item.PushResult = PushResult.Active;
                item.DistributorHotelId = hotelInfo.DistributorHotelId;
                item.DistributorRoomId = "XXX" + item.RoomId;
            });
            return new ResultData<CDistributorHotel> { Success = true, Data = new CDistributorHotel { dHotel = hotelInfo, dRoomList = roomList } };
        }
    }
}
